package com.suixun.controller.count;

import javax.annotation.Resource;

import org.jsoup.helper.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.authority.controller.BaseManager;
import com.suixun.entity.StdCountBasic;
import com.suixun.service.count.StdCountBasicService;
@Controller
@RequestMapping(value = "/count")
public class StdCountBasicManager extends BaseManager{

	@Resource
	private StdCountBasicService stdCountBasicService;
	
	@RequestMapping(value = "listBasic.json")
	@ResponseBody
	public Object listBasic(){
	
		return success(stdCountBasicService.list());
	}
	
	/**
	 * 
	 * @param name
	 * @param beginTime
	 * @param endTime
	 * @param appFrom
	 * @param orgId
	 * @param orgType province省  city市  town区
	 * @return
	 */
	@RequestMapping(value = "listResult.json")
	@ResponseBody
	public Object listResult(String name, String beginTime, String endTime, Integer appFrom, String orgId, String orgType){
		
		StdCountBasic scb = stdCountBasicService.getByName(name);
		if(scb == null){
			fail("请选择业务统计名称");
		}
		
		String sql = "";
		if(appFrom == 0){
			sql = stdCountBasicService.installSqlByTeacherAndGuardian(orgId, orgType, scb, beginTime, endTime);
		}else{
			sql = stdCountBasicService.installSqlSelf(orgId, orgType, scb, appFrom, beginTime, endTime);
		}
		
		if(StringUtil.isBlank(sql)){
			return success();
		}
		
		return success(stdCountBasicService.listResult(sql));
	}
	
}
